{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Find Indices With Index and Value Difference I"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #array"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #数组"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: findIndices"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #找出满足差值条件的下标 I"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你一个下标从 <strong>0</strong> 开始、长度为 <code>n</code> 的整数数组 <code>nums</code> ，以及整数 <code>indexDifference</code> 和整数 <code>valueDifference</code> 。</p>\n",
    "\n",
    "<p>你的任务是从范围 <code>[0, n - 1]</code> 内找出&nbsp; <strong>2</strong> 个满足下述所有条件的下标 <code>i</code> 和 <code>j</code> ：</p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>abs(i - j) &gt;= indexDifference</code> 且</li>\n",
    "\t<li><code>abs(nums[i] - nums[j]) &gt;= valueDifference</code></li>\n",
    "</ul>\n",
    "\n",
    "<p>返回整数数组 <code>answer</code>。如果存在满足题目要求的两个下标，则 <code>answer = [i, j]</code> ；否则，<code>answer = [-1, -1]</code> 。如果存在多组可供选择的下标对，只需要返回其中任意一组即可。</p>\n",
    "\n",
    "<p><strong>注意：</strong><code>i</code> 和 <code>j</code> 可能 <strong>相等</strong> 。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>nums = [5,1,4,1], indexDifference = 2, valueDifference = 4\n",
    "<strong>输出：</strong>[0,3]\n",
    "<strong>解释：</strong>在示例中，可以选择 i = 0 和 j = 3 。\n",
    "abs(0 - 3) &gt;= 2 且 abs(nums[0] - nums[3]) &gt;= 4 。\n",
    "因此，[0,3] 是一个符合题目要求的答案。\n",
    "[3,0] 也是符合题目要求的答案。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>nums = [2,1], indexDifference = 0, valueDifference = 0\n",
    "<strong>输出：</strong>[0,0]\n",
    "<strong>解释：</strong>\n",
    "在示例中，可以选择 i = 0 和 j = 0 。 \n",
    "abs(0 - 0) &gt;= 0 且 abs(nums[0] - nums[0]) &gt;= 0 。 \n",
    "因此，[0,0] 是一个符合题目要求的答案。 \n",
    "[0,1]、[1,0] 和 [1,1] 也是符合题目要求的答案。 \n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 3：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>nums = [1,2,3], indexDifference = 2, valueDifference = 4\n",
    "<strong>输出：</strong>[-1,-1]\n",
    "<strong>解释：</strong>在示例中，可以证明无法找出 2 个满足所有条件的下标。\n",
    "因此，返回 [-1,-1] 。</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>1 &lt;= n == nums.length &lt;= 100</code></li>\n",
    "\t<li><code>0 &lt;= nums[i] &lt;= 50</code></li>\n",
    "\t<li><code>0 &lt;= indexDifference &lt;= 100</code></li>\n",
    "\t<li><code>0 &lt;= valueDifference &lt;= 50</code></li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [find-indices-with-index-and-value-difference-i](https://leetcode.cn/problems/find-indices-with-index-and-value-difference-i/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [find-indices-with-index-and-value-difference-i](https://leetcode.cn/problems/find-indices-with-index-and-value-difference-i/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['[5,1,4,1]\\n2\\n4', '[2,1]\\n0\\n0', '[1,2,3]\\n2\\n4']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findIndices(self, nums: List[int], indexDifference: int, valueDifference: int) -> List[int]:\n",
    "        ans = [-1, -1]\n",
    "        l = len(nums)\n",
    "        for i in range(l-indexDifference):\n",
    "            for j in range(i+indexDifference, l):\n",
    "                if abs(nums[i]-nums[j]) >= valueDifference:\n",
    "                    ans = [i, j]\n",
    "                    return ans\n",
    "        return ans\n",
    "                    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findIndices(self, nums: List[int], indexDifference: int, valueDifference: int) -> List[int]:\n",
    "        def func(nums,indexDifference,valueDifference):\n",
    "            n = len(nums)\n",
    "\n",
    "            for i in range(indexDifference,n):\n",
    "                for j in range(i-indexDifference+1):\n",
    "                    if abs(nums[i]-nums[j])>=valueDifference:\n",
    "                        return [i,j]\n",
    "\n",
    "            return [-1,-1]\n",
    "        \n",
    "        return func(nums,indexDifference,valueDifference)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findIndices(self, nums: List[int], indexDifference: int, valueDifference: int) -> List[int]:\n",
    "        ans=[-1,-1]\n",
    "        for i in range(len(nums)-indexDifference):\n",
    "            for j in range(i+indexDifference,len(nums)):\n",
    "                if abs(nums[i]-nums[j])>=valueDifference:\n",
    "                    ans[0]=i\n",
    "                    ans[1]=j\n",
    "                    break\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findIndices(self, nums: List[int], indexDifference: int, valueDifference: int) -> List[int]:\n",
    "        n = len(nums)\n",
    "        for i in range(n-indexDifference):\n",
    "            for j in range(i+indexDifference, n):\n",
    "                if abs(nums[i] - nums[j]) >= valueDifference:\n",
    "                    return [i, j]\n",
    "\n",
    "        return [-1, -1]"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
